<?php

$api = app('Dingo\Api\Routing\Router');

$params = [
    'middleware' => [
        'api.throttle',
        'serializer:array', // 减少transformer的包裹层
        'bindings' // 支持路由模型注入
    ],
    'limit' => 60,
    'expires' => 1
];

$api->version('v1',$params, function ($api) {

    //路由前缀admin
    $api->group(['prefix'=>'admin'],function ($api){
        //需要登录的路由
        $api->group(['middleware'=>['api.auth', 'check.permission']],function ($api){

            /**
             * 用户
             */
            //禁用用户/启用用户
            $api->patch('users/{user}/lock',[\App\Http\Controllers\Admin\UserController::class,'lock'])->name('users.lock');
            //用户管理资源路由
            $api->resource('users',\App\Http\Controllers\Admin\UserController::class,[
                'only' => ['index','show']
            ]);

            /**
             * 分类
             */
            //禁用分类/启用分类
            $api->patch('category/{category}/status',[\App\Http\Controllers\Admin\CategoryController::class,'status'])->name('category.status');
            //分类管理资源路由
            $api->resource('category',\App\Http\Controllers\Admin\CategoryController::class,[
                'except'=>['destroy']
            ]);

            /**
             * 商品
             */
            //上架商品
            $api->patch('goods/{good}/on',[\App\Http\Controllers\Admin\GoodsController::class,'isOn'])->name('goods.on');

            //推荐商品
            $api->patch('goods/{good}/recommend',[\App\Http\Controllers\Admin\GoodsController::class,'isRecommend'])->name('goods.recommend');

            //商品管理资源路由
            $api->resource('goods',\App\Http\Controllers\Admin\GoodsController::class,[
                'except'=>['destroy']
            ]);

            /**
             * 评价
             */
            //评价列表
            $api->get('comments',[\App\Http\Controllers\Admin\CommentController::class,'index'])->name('comments.index');
            //评价详情
            $api->get('comments/{comment}',[\App\Http\Controllers\Admin\CommentController::class,'show'])->name('comments.show');
            //商家回复
            $api->patch('comments/{comment}/reply',[\App\Http\Controllers\Admin\CommentController::class,'reply'])->name('comments.reply');

            /**
             * 订单
             */
            //订单列表
            $api->get('orders',[\App\Http\Controllers\Admin\OrderController::class,'index'])->name('orders.index');
            //订单详情
            $api->get('orders/{order}',[\App\Http\Controllers\Admin\OrderController::class,'show'])->name('orders.show');
            //发货
            $api->patch('orders/{order}/post',[\App\Http\Controllers\Admin\OrderController::class,'post'])->name('orders.post');

            /**
             * 轮播图
             */
            //轮播图排序
            $api->patch('slides/{slide}/seq',[\App\Http\Controllers\Admin\SlideController::class,'seq'])->name('slides.seq');

            // 轮播图禁用和启用
            $api->patch('slides/{slide}/status', [\App\Http\Controllers\Admin\SlideController::class, 'status']);

            //轮播图管理资源路由
            $api->resource('slides',\App\Http\Controllers\Admin\SlideController::class);
            /**
             * 菜单
             */
            //菜单列表
            $api->get('menus',[\App\Http\Controllers\Admin\MenuController::class,'index'])->name('menus.index');
        });
    });

});
